Retrieve data from PostgreSQL Database using ADO.Net "System.Data.Odbc" (VB.Net)
NickName:Asfand Iqbal Ask DateTime:2013-04-12T18:28:07

Retrieve data from PostgreSQL Database using ADO.Net "System.Data.Odbc" (VB.Net)

Though I have been using SQL Server, Oracle from last decade, I have been asked to do some research on PostgreSQL and after some initial investigation it is evident that I am now stuck on retrieving data from the PostgreSQL database using Function.

Using following piece of code to retrieve the data and getting error ('ERROR [26000] ERROR: prepared statement "mytabletest" does not exist; 'Error while executing the query)


Code Snippets

    Dim oDBCommand As DbCommand = GetDBCommand(oConnectionType, "mytabletest", CommandType.StoredProcedure)
    Dim dstResults As DataSet = GetDataSet(ConnectionTypes.ODBC, oDBCommand)


Public Function GetDataReader(dbType As ConnectionTypes, command As DbCommand) As DbDataReader

    Try

        Dim oConnection As DbConnection = GetDBConnection(dbType)

        Dim oDBTransaction As DbTransaction = oConnection.BeginTransaction
        command.Connection = oConnection
        command.Transaction = oDBTransaction


   'GETTING ERROR ON FOLLOWING LINE
        'ERROR [26000] ERROR: prepared statement "mytabletest" does not exist;
        'Error while executing the query
        return command.ExecuteReader()


    Catch ex As Exception
        Throw ex
    Finally
    End Try

    Return Nothing

End Function

Environement I am currently working on is following:-

32 Bit Machine. 
Visual Studio 2010 + SP1 
ODBC Prodiver: PostgreSQL Unicode 9.01.02.00
ADO.Net (System.Data.Odbc)

Please note that I am open to any suggestions i.e. if I am completely doing it wrong OR partially etc. Please feel free to write.

In order to make it easier for you to create a same environment, please use following table/function definition.

--- Simple table to make things easier to understand. <br>
CREATE TABLE mytable
(
  messagetypeid integer NOT NULL,
  messagetype character varying(100) NOT NULL
) 



-- Function to retrieve data. <br>
CREATE OR REPLACE FUNCTION mytabletest()  <br>
   RETURNS SETOF refcursor AS $$
    DECLARE 
    ref1 refcursor; 
    BEGIN
      OPEN ref1 FOR SELECT * FROM mytable;
      RETURN NEXT ref1;                                                                               
    END;
    $$ LANGUAGE plpgsql;

Please Note:

If I use <br>
  Dim oDBCommand As DbCommand = GetDBCommand(oConnectionType, "SELECT * FROM mytable", CommandType.Text) 

then system manages to retrieve information from the datbase without any issue, however, as I mentioned as soon we use "Function" it throws an exception.


During my failed efforts to search any solution from the internet someone mentioned that Table should be created with the lower case it so just for the sake of it I recreated with the lower case, however, problem persists.

Copyright Notice:Content Author:「Asfand Iqbal」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15968999/retrieve-data-from-postgresql-database-using-ado-net-system-data-odbc-vb-net

More about “Retrieve data from PostgreSQL Database using ADO.Net "System.Data.Odbc" (VB.Net)” related questions

Connecting ado.net Entity data model to postgresql database

I'm new to C#, ado.net and visual studio 2012, just to make that clear from the beginning. I'm trying to connect an ADO.NET Entity Data Model to a postgresql database. I tell VS to 'generate mdoel...

Show Detail

Retrieve data from PostgreSQL Database using ADO.Net "System.Data.Odbc" (VB.Net)

Though I have been using SQL Server, Oracle from last decade, I have been asked to do some research on PostgreSQL and after some initial investigation it is evident that I am now stuck on retrieving

Show Detail

Connect ADO.NET Entity Data Model to Postgresql database

I'm creating an ASP MVC 3 website. I have a Postgresql database - I'm using Entity Framework 6 - I have referenced Npgsql and Npgsql.EntityFramework and installed dotConnect for PostgreSQL. The

Show Detail

Fastest way to retrieve data from a database in .NET?

Using ADO.NET, what is the fastest way to retrieve data from the database and populate the data into my business objects? Which one should I use? DBDataReader , DBDataAdapter, or any other classes...

Show Detail

MultipleActiveResultSets for postgresql and ado.net entity data model

Im using visual studio, postgresql database and ado.net entity data model. In the connectionstring, Im unable set MultipleActiveResultSets=True. Usually when I connect to sql server with

Show Detail

how to use postgresql with ado.net entity framework in asp.net mvc 2

In my current project, we are using visual studio 2008, sql server 2008, mvc 2 with ado.net entity framework (ado.net entity data model), linq and developing a web application. This application wor...

Show Detail

Postgres Database not available in ADO.NET Entity Data Model

I am trying to create entities from a postgres database using the Visual Studio ADO.NET Entity Data Model, however Postgres Database is not listed as one of the data sources. I have installed dotc...

Show Detail

Retrieve data from PostgreSQL Database using ADO.Net “System.Data.Odbc” (VB.Net)

I have been asked to do some research on PostgreSQL and after running the following piece of code system returns two entries (Unnamed Portal 1 and Unnamed Portal 2) when we read DBDataReader obje...

Show Detail

How to retrieve data using EF Database First

I have a console application. I'm trying to use EF Database First. I used ADO.NET Entity Data Model, then EF Designer from Database. Then I connected to the database, and classes are generated. Now...

Show Detail

Retrieve data from postgresql DB without django models

I have googled tutorials/examples on how to retrieve data from a postgresql database which already has tables, but most of the them are using Models. As in they are tutorials about making a DB from

Show Detail